package com.vm.osm.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.vm.osm.business.dao.EamEquTypeMapper;
import com.vm.osm.business.dto.rsp.RspEquTypeDetail;
import com.vm.osm.business.dto.rsp.RspEquTypePage;
import com.vm.osm.business.entity.EamEquType;
import com.vm.osm.business.service.IEquTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhangshilin on 2018/1/7.
 */
@Service
public class EquTypeServiceImpl implements IEquTypeService {
    @Autowired
    private EamEquTypeMapper eamEquTypeMapper;

    @Override
    public int deleteByPrimaryKey(String id) {
        return eamEquTypeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(EamEquType record) {
        return eamEquTypeMapper.insert(record);
    }

    @Override
    public int insertSelective(EamEquType record) {
        return eamEquTypeMapper.insertSelective(record);
    }

    @Override
    public EamEquType selectByPrimaryKey(String id) {
        return eamEquTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(EamEquType record) {
        return eamEquTypeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(EamEquType record) {
        return eamEquTypeMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<RspEquTypePage> findPage(String enterpriseId) {
        //一级
        List<RspEquTypePage> firstList = eamEquTypeMapper.findByParentId(enterpriseId,null);
        for (RspEquTypePage rspEquTypePage:firstList){
            //二级
            List<RspEquTypePage> secondList = eamEquTypeMapper.findByParentId(enterpriseId,rspEquTypePage.getId());
            for (RspEquTypePage rspEquTypePage1:secondList){
                //三级
                List<RspEquTypePage> thirdList = eamEquTypeMapper.findByParentId(enterpriseId,rspEquTypePage1.getId());
                for (RspEquTypePage rspEquTypePage2:thirdList){
                    //四级
                    List<RspEquTypePage> fourList = eamEquTypeMapper.findByParentId(enterpriseId,rspEquTypePage2.getId());
                    rspEquTypePage2.setChildren(fourList);
                }
                rspEquTypePage1.setChildren(thirdList);
            }
            rspEquTypePage.setChildren(secondList);
        }
        return firstList;
    }

    @Override
    public RspEquTypeDetail findDetail(String id) {
        return eamEquTypeMapper.findDetail(id);
    }
}
